<template>
	<view class="main">
		<sw-team style="margin-bottom: 20rpx;" :teamName="teamName" :singleTean="singleTean" v-show="!noTeam"></sw-team>
		<view>
			<search-top style="border-top: 1px solid #e8e8e8;padding: 20rpx 0;" placeholder="请输入关键词" @mySearch="mySearch"></search-top>
		</view>
		<view class="box">
			<view class="box_content" v-for="n in list" :key="n.id">
				<view class="box_title">
					{{n.title}}
				</view>
				<view class="action">
					<view class="left" @click="goDetails(n)">
						 问卷详情
					</view>
					<view class="right" @click="goRecord(n)">
						填写记录
					</view>
				</view>
			</view>
			<view class="empty" v-if="empty">
				<u-image width="273rpx" height="273rpx" :src="emptyImg"></u-image>
				<view class="txt">
					暂无问卷
				</view>
			</view>
		</view>
		<go-nav></go-nav>
	</view>
</template>

<script>
	import {
		getTeamByUser,
		wenjuanList
	} from '@/api/index.js'
	import {
		chooseTeamNow
	} from '@/utils/index.js'
	import swTeam from './component/sw-team/sw-team.vue'
	import pageMixinNorRequest from '@/utils/pageMixinNorRequest.js' //在需要引入的组件中引入
	export default {
		mixins: [pageMixinNorRequest],
		components: {
			'sw-team': swTeam
		},
		data() {
			return {
				teamName: '',
				noTeam: false,
				singleTean: false,
				emptyImg: require('@/static/img/empty_hcem.png'),
				teamId: '',
				searchWord: ''
			};
		},
		async onShow() {
			await this.getTeamList()
			this.clearPageStatus()
			await this.getTeam()
		},
		methods: {
			async getMyList(obj) { //请求,这个最好在使用那个组件中使用，这个地方可以扩展接参数
				//例如， {..obj,id:15}
				// let res = await getTeamByUser(obj)
				let params = {
					titleName: this.searchWord
				}
				if (this.teamId) { //有团队传团队id。没有传个人id
					params.teamId = this.teamId
				} else {
					//let userId = uni.getStorageSync('userinfo').user.userId
					params.teamId = 0
				}
				let res = await wenjuanList({
					...obj,
					...params
				})
				//console.log(res);
				return res
			},
			async getTeamList() {
				await chooseTeamNow()
				let ress = uni.getStorageSync('myTeam')
				if (ress && ress?.code == 200) {
					this.teamName = ress.data.name
					this.teamId = ress.data.id
				} else {
					this.noTeam = true
				}
				let res = await getTeamByUser({
					pageNum: 1,
					pageSize: 15
				})
				if (res.code == 200) {

					if (res.rows.length == 0) {
						this.noTeam = true

					} else {
						if (res.rows.length == 1) {
							this.singleTean = true
						}
					}
				}
			},
			mySearch(val) {  //搜索
				this.searchWord = val
				this.clearPageStatus()
				this.getTeam()
			},
			goRecord(obj) {
				uni.navigateTo({
					url: `/pages/wenjuan/record?id=${obj.id}&title=${obj.title}`
				})
			},
			async goDetails(obj){
				window.location.href = obj.previewUrl
				console.log('详情',obj);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.box {
			background-color: #f8f8f8;
			min-height: 100vh;
			padding-top: 24rpx;

			.box_content {
				//	padding-top: 100rpx;
				margin: 0 24rpx 24rpx 24rpx;
				height: 200rpx;
				background-color: #fff;
				border-radius: 20rpx;

				.box_title {
					font-weight: bold;
					font-size: 32rpx;
					color: #212121;
					line-height: 38rpx;
					padding: 32rpx 24rpx;
					border-bottom: 1px solid $-line-color;
				}

				.action {
					display: flex;
					align-items: center;
					//justify-content: center;
					font-weight: bold;
					font-size: 28rpx;
					color: #4DC0D9;
					line-height: 33rpx;

					.left {
						width: 350rpx;
						text-align: center;
						padding: 32rpx 0;
						border-right: 1px solid #e8e8e8;
					}

					.right {
						width: 350rpx;
						text-align: center;
						padding: 32rpx 0;
					}
				}
			}

			.empty {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				padding-top: 330rpx;

				.txt {
					font-weight: 500;
					font-size: 32rpx;
					color: #C7C7C7;
					padding-top: 40rpx;
					line-height: 38rpx;
				}
			}
		}
	}
</style>